package entity;

import java.util.*;
import entity.Database.*;

public class Column 
{
	private String Name;
	private DataType Type;
	private List<String> datas;
	private boolean isPrimaryKey;
	public Column()
	{
		datas = new ArrayList<String>();
	}
	public Column(String Name,DataType Type,boolean isPrimaryKey)
	{
		this.Name = Name;
		this.Type = Type;
		this.isPrimaryKey = isPrimaryKey;
		datas = new ArrayList<String>();
	}
	public String getName()
	{
		return this.Name;
	}
	public void setName(String newName)
	{
		this.Name = newName;
	}
	
	public DataType getType()
	{
		return this.Type;
	}
	
	public void setType(DataType Type)
	{
		this.Type = Type;
	}
	
	public boolean IsPrimaryKey()
	{
		return isPrimaryKey;
	}
	
	public void setPrimaryKey(boolean isPrimaryKey)
	{
		this.isPrimaryKey = isPrimaryKey;
	}
	public int getDataCount()
	{
		return this.datas.size();
	}
	
	public int getDataIndex(String Data)
	{
		for (int i=0;i<datas.size();i++) if (datas.get(i).compareTo(Data)==0) return i;
		return -1; 
	}
	
	public boolean addData(String Data)
	{
		if (isPrimaryKey) 
		{
			int index = getDataIndex(Data);
			if (index!=-1) return false;
		}
		datas.add(Data);
		return true;
	}
	
	public String getDataAt(int index)
	{
		try
		{
			return this.datas.get(index);
		}
		catch (IndexOutOfBoundsException IOOBE)
		{
			return null;
		}
	}
	
	public boolean setDataAt(int index, String data)
	{
		try
		{
			this.datas.set(index, data);
		}
		catch (IndexOutOfBoundsException IOOBE)
		{
			return false;
		}
		return true;
	}
	
	
	public boolean removeDataAt(int index)
	{
		try
		{
			this.datas.remove(index);
			return true;
		}
		catch (IndexOutOfBoundsException IOOBE)
		{
			return false;
		}
	}
	public void clearData()
	{
		this.datas.clear();
	}

}
